﻿using System;
using Combinatorics.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SOM.Model
{
    public class nGrammDictionary
    {
        public Dictionary<String, int> wordDictionary = new Dictionary<String, int>();
        public int nGramlenght;
        public int DictSize;

        public nGrammDictionary(nGrammDictionary Dict)
        {
            this.wordDictionary = new Dictionary<string, int>(Dict.wordDictionary);
            this.nGramlenght = Dict.nGramlenght;
        }

        public nGrammDictionary(int wordlength, int DSize)
        {
            int NumberNukl;                       //number of nukleotide 1='A',2='T',3='C',4= 'G'    
            Random rand = new Random();           // Instantiate random number generator using system-supplied value as seed.
            nGramlenght = wordlength;
            DictSize = DSize;
            if (nGramlenght > 6)                  //option that is not contain all possible words 
            {
                for (int i = 0; i < DictSize; i++)
                {
                    StringBuilder nGram = new StringBuilder();
                    for (int j = 0; j < nGramlenght; j++)
                    {
                        NumberNukl = rand.Next(1, 5);
                        switch (NumberNukl)
                        {
                            case 1:
                                nGram.Append('A');
                                break;
                            case 2:
                                nGram.Append('T');
                                break;
                            case 3:
                                nGram.Append('C');
                                break;
                            case 4:
                                nGram.Append('G');
                                break;
                            default:
                                Console.WriteLine("Default case");
                                break;
                        }


                    }
                    try
                    {
                        wordDictionary.Add(nGram.ToString(), 0);
                    }
                    catch (Exception e)
                    {
                        i--;
                    }
                }

            }//end of if length(ngramm) >6
            else   ///length(ngramm) =6
            {
                var NucleotidesSet = new List<string> { "A", "T", "C", "G" };
                var v = new Variations<string>(NucleotidesSet, 6, GenerateOption.WithRepetition);//Variations with Repetition
                foreach (var vv in v)
                {
                    try
                    {
                        wordDictionary.Add(String.Join("", vv.ToArray()), 0);
                    }
                    catch (Exception e)
                    {
                        //warning "not adding string to dictionary"
                    }

                }

            }//end of  else length(ngramm) =6
        }
    }
}


